//
//  NSDictionary+nilHandle.m
//  DaFangYa
//
//  Created by lizhenqiang on 15/9/27.
//  Copyright © 2015年 HFKJ_LZQ. All rights reserved.
//

#import "NSDictionary+nilHandle.h"

@implementation NSDictionary (nilHandle)

+(id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}
-(NSMutableDictionary *)signDic:(NSMutableDictionary *)dic andToken:(NSString *)token andSecret:(NSString *)secret
{
    if (![NSString isEmpty:token]) {
        if (dic!=nil) {
            [dic setObject:token forKey:@"pt_token"];
        }
    }
    NSString *signFirstStr = [NSString sortRequestData:dic];
    signFirstStr = [signFirstStr stringByAppendingString:[NSString stringWithFormat:@"%@",secret]];
    if ([NSString isEmpty:signFirstStr]) {
        return nil;
    }
    NSString *md5SignStr = [NSString MD5:signFirstStr];
    [dic setObject:md5SignStr forKey:@"pt_sign"];
    return dic;
}
@end
